﻿using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using Sundstrom.Validation;

namespace Sundstrom.Mvvm.Validation
{
    public static class DataAnnotationValidator
    {
        public static bool ValidateProperty(object obj, string propertyName, object value,
            out List<ValidationResult> results)
        {
            Contract.Requires<ArgumentException>(obj != null);
            Contract.Requires<ArgumentException>(!string.IsNullOrEmpty(propertyName));

            results = new List<ValidationResult>(1);

            bool result = Validator.TryValidateProperty(
                obj,
                propertyName,
                results);

            return result;
        }
    }
}